{% extends 'base.html' %}

{% block title %}首页 - 请假审批系统{% endblock %}

{% block content %}
<div class="card">
    <div class="card-header">
        <h2>欢迎回来，{{ user.get_full_name|default:user.username }}！</h2>
    </div>
    
    <div class="stats-grid">
        <div class="stat-card">
            <div class="stat-number">{{ user_stats.total_applications }}</div>
            <div class="stat-label">今年总申请</div>
        </div>
        <div class="stat-card">
            <div class="stat-number">{{ user_stats.approved_applications }}</div>
            <div class="stat-label">已批准申请</div>
        </div>
        <div class="stat-card">
            <div class="stat-number">{{ user_stats.total_days }}</div>
            <div class="stat-label">今年请假天数</div>
        </div>
        <div class="stat-card">
            <div class="stat-number">{{ user.userprofile.remaining_leave_days }}</div>
            <div class="stat-label">剩余年假天数</div>
        </div>
    </div>
</div>

<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 2rem;">
    <div class="card">
        <div class="card-header">
            <h2>最近申请</h2>
        </div>
        
        {% if recent_applications %}
        <table class="table">
            <thead>
                <tr>
                    <th>请假类型</th>
                    <th>开始日期</th>
                    <th>天数</th>
                    <th>状态</th>
                </tr>
            </thead>
            <tbody>
                {% for application in recent_applications %}
                <tr>
                    <td>{{ application.leave_type.name }}</td>
                    <td>{{ application.start_date }}</td>
                    <td>{{ application.days_requested }}天</td>
                    <td>
                        <span class="status-badge status-{{ application.status }}">
                            {{ application.get_status_display }}
                        </span>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        <div style="text-align: center; margin-top: 1rem;">
            <a href="{% url 'my_leaves' %}" class="btn btn-primary">查看全部</a>
        </div>
        {% else %}
        <p style="text-align: center; color: #666; padding: 2rem;">暂无申请记录</p>
        <div style="text-align: center;">
            <a href="{% url 'apply_leave' %}" class="btn btn-primary">立即申请</a>
        </div>
        {% endif %}
    </div>

    <div class="card">
        <div class="card-header">
            <h2>待处理事项</h2>
        </div>
        
        {% if pending_approvals %}
        <div style="margin-bottom: 1rem;">
            <strong>待审批申请：{{ pending_approvals|length }}个</strong>
        </div>
        <table class="table">
            <thead>
                <tr>
                    <th>申请人</th>
                    <th>请假类型</th>
                    <th>开始日期</th>
                    <th>天数</th>
                </tr>
            </thead>
            <tbody>
                {% for application in pending_approvals|slice:":5" %}
                <tr>
                    <td>{{ application.applicant.get_full_name|default:application.applicant.username }}</td>
                    <td>{{ application.leave_type.name }}</td>
                    <td>{{ application.start_date }}</td>
                    <td>{{ application.days_requested }}天</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        <div style="text-align: center; margin-top: 1rem;">
            <a href="{% url 'approval_list' %}" class="btn btn-warning">去审批</a>
        </div>
        {% else %}
        <p style="text-align: center; color: #666; padding: 2rem;">暂无待审批事项</p>
        {% endif %}
    </div>
</div>

<div class="card">
    <div class="card-header">
        <h2>快速操作</h2>
    </div>
    
    <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem;">
        <a href="{% url 'apply_leave' %}" class="btn btn-primary">申请请假</a>
        <a href="{% url 'my_leaves' %}" class="btn btn-secondary">我的申请</a>
        {% if user.userprofile.can_approve_leave %}
        <a href="{% url 'approval_list' %}" class="btn btn-warning">待审批列表</a>
        {% endif %}
        <a href="{% url 'profile' %}" class="btn btn-secondary">个人资料</a>
    </div>
</div>
{% endblock %}
